package com.jww.hwork04;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Demo07_context extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext =getServletContext();

        servletContext.setAttribute("username", "zhangsan");
        String servletContextInof = servletContext.getInitParameter("servletContextInof");
        System.out.println("servletContextInof = " + servletContextInof);

        String globalEncoding = servletContext.getInitParameter("globalEncoding");
        System.out.println("globalEncoding = " + globalEncoding);

        String servletContextName = servletContext.getServletContextName();
        System.out.println("servletContextName = " + servletContextName);

        String realPath = servletContext.getRealPath(servletContextName);
        System.out.println("realPath = " + realPath);

        String contextPath = servletContext.getContextPath();
        System.out.println("contextPath = " + contextPath);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
